import { EntitySchema, Ref } from '@mikro-orm/core';
import { Users } from './Users';

export class Accounts {
  id!: string;
  createdAt?: Date;
  updatedAt?: Date;
  user!: Ref<Users>;
  accountType!: string;
  lastLoginAt?: Date;
  email?: string;
  emailVerifiedAt?: Date;
  phoneNumber?: string;
  phoneVerifiedAt?: Date;
  password?: string;
  openid?: string;
  unionid?: string;
  sessionKey?: string;
  wxRegisterAt?: Date;
}

export const AccountsSchema = new EntitySchema({
  class: Accounts,
  properties: {
    id: { primary: true, type: 'string', columnType: 'bigint' },
    createdAt: { type: 'Date', length: 0, nullable: true },
    updatedAt: { type: 'Date', length: 0, nullable: true },
    user: { reference: '1:1', entity: () => Users, ref: true },
    accountType: { type: 'string', length: 255 },
    lastLoginAt: { type: 'Date', length: 0, nullable: true },
    email: { type: 'string', length: 255, nullable: true, unique: 'accounts_email_unique' },
    emailVerifiedAt: { type: 'Date', length: 0, nullable: true },
    phoneNumber: { type: 'string', length: 255, nullable: true },
    phoneVerifiedAt: { type: 'Date', length: 0, nullable: true },
    password: { type: 'string', length: 255, nullable: true },
    openid: {
      type: 'string',
      length: 255,
      nullable: true,
      unique: 'accounts_openid_unique',
    },
    unionid: {
      type: 'string',
      length: 255,
      nullable: true,
      unique: 'accounts_unionid_unique',
    },
    sessionKey: { type: 'string', length: 255, nullable: true },
    wxRegisterAt: { type: 'Date', length: 0, nullable: true },
  },
});
